package com.puris.dao.admin;

import com.puris.dao.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Sonata
 * @data 2021/11/28 15:32
 */
public class DeleteTeacherDaoImpl implements DeleteTeacherDao {
    @Override
    public boolean deleteTeacher(Connection connection, String id) throws SQLException {
        PreparedStatement statement = null;
        int rows1 = 0;
        int rows2 = 0;

        if (connection != null) {
            String sql = "delete from teacher where id = ?";
            Object[] params = {id};

            rows1 = BaseDao.execute(connection, statement, sql, params);
        }
        BaseDao.closeResource(null, statement, null);

        if (connection != null) {
            String sql = "delete from competiton where teacher_id = ?";
            Object[] params = {id};

            rows2 = BaseDao.execute(connection, statement, sql, params);
        }
        BaseDao.closeResource(null, statement, null);

        return (rows1 != 0 && rows2 != 0);
    }
}
